import { Configuration, App } from "@midwayjs/core";
import * as koa from "@midwayjs/koa";
import * as validate from "@midwayjs/validate";
import * as info from "@midwayjs/info";
import { join } from "path";
// import { DefaultErrorFilter } from './filter/default.filter';
// import { NotFoundFilter } from './filter/notfound.filter';
import { ReportMiddleware } from "./middleware/report.middleware";

import * as captcha from "@midwayjs/captcha";
import * as orm from "@midwayjs/typeorm";

import * as swagger from "@midwayjs/swagger";

import * as upload from "@midwayjs/upload";

import * as staticFile from "@midwayjs/static-file";

import * as jwt from "@midwayjs/jwt";
import { JwtMiddleware } from "./middleware/jwt.middleware";

import * as crossDomain from "@midwayjs/cross-domain";

import * as cache from "@midwayjs/cache";

require("events").EventEmitter.defaultMaxListeners = 0;

@Configuration({
  imports: [
    koa,
    validate,
    {
      component: info,
      enabledEnvironment: ["local"]
    },
    jwt,
    crossDomain,
    captcha,
    orm,
    upload,
    staticFile,
    cache,
    {
      component: swagger,
      enabledEnvironment: ["local"]
    }
  ],
  importConfigs: [join(__dirname, "./config")]
})
export class ContainerLifeCycle {
  @App()
  app: koa.Application;

  async onReady() {
    // add middleware
    this.app.useMiddleware([ReportMiddleware, JwtMiddleware]);

    // add filter
    // this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
  }
}
